import requests


class KDTXApi:

    # 封装生成验证码接口
    @classmethod
    def get_code_api(cls):
        code_url = "http://kdtx-test.itheima.net/api/captchaImage"
        code_resp = requests.get(url=code_url)
        return code_resp

    @classmethod
    def login_api(cls, login_body):
        login_url = "http://kdtx-test.itheima.net/api/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

        # 上传合同接口

    @classmethod
    def upload_contract_api(cls, token, f):
        url = "http://kdtx-test.itheima.net/api/common/upload"
        headers = {"Authorization": token}
        resp = requests.post(url=url, headers=headers, files={"file": f})
        return resp
        pass

    #封装添加课程接口
    @classmethod
    def add_course_api(cls,token,body):
        url="http://kdtx-test.itheima.net/api/clues/course"
        header={"Authorization":token,"content-type":"application/json"}
        resp =requests.post(url=url,headers=header,json=body)
        return resp
        pass

    #封装查询课程列表接口
    @classmethod
    def qeury_course_api(cls,token):
        url="http://kdtx-test.itheima.net/api/clues/course/list"
        header={"Authorization":token}
        resp =requests.get(url=url,headers=header)
        return resp
    #封装修改课程接口
    @classmethod
    def update_course_api(cls,token,body):
        url="http://kdtx-test.itheima.net/api/clues/course"
        headers={"Authorization":token,"content-type":"application/json"}
        resp =requests.put(url=url,headers=headers,json=body)
        return resp
    #封装删除课程接口
    @classmethod
    def del_course_api(cls,token,id):
        url=f"http://kdtx-test.itheima.net/api/clues/course/{id}"
        headers={"Authorization":token}
        resp =requests.delete(url=url,headers=headers)
        return resp
        pass


